//
//  LKMyOrderCheckDetailViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/5/10.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKMyOrderCheckDetailViewController.h"
#import "LKMyContinuInvestFillCell.h"
#import "LKWriteContinuInvestCell.h"
#import "LKWorkOrderDetailContractCell.h"
#import "LKMyOrderCheckStatuCell.h"

@interface LKMyOrderCheckDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)LKBaseTableview *tableView;
@property(nonatomic,strong)NSArray *contentsArray;
@property(nonatomic,strong)NSArray *titlesArray;
@property(nonatomic,strong)NSString *contractCode;
@property(nonatomic,strong)NSString *status;
@property(nonatomic,copy)NSString *shengmingUrl;
@end

@implementation LKMyOrderCheckDetailViewController
-(LKBaseTableview *)tableView{
    if (!_tableView) {
        _tableView = [LKBaseTableview setTableviewWithFrame:CGRectMake(0, 12 + NAVIGATION_BAR_HEIGHT, WIDTH, HEIGHT - (NAVIGATION_BAR_HEIGHT + 12)) style:UITableViewStyleGrouped registercellClasss:@[@"LKMyContinuInvestFillCell",@"LKWriteContinuInvestCell",@"LKWorkOrderDetailContractCell",@"LKMyOrderCheckStatuCell"]];
        [self.view addSubview:_tableView];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.estimatedRowHeight = 200;
    [self getDetailInformation];
    // Do any additional setup after loading the view.
    
}
-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    self.navigationItem.title = @"审批";
//    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//    btn.titleLabel.font = [UIFont systemFontOfSize:16];
//    [btn setTitle:@"确定" forState:UIControlStateNormal];
//    [btn setTitleColor:blueDefault forState:UIControlStateNormal];
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 2) {
        return self.titlesArray.count;
    }
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LKWriteContinuInvestCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKWriteContinuInvestCell"];
    if (indexPath.section == 0) {
        LKMyOrderCheckStatuCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKMyOrderCheckStatuCell"];
        cell.statusLabel.text = self.status;
        return cell;
    }
    if (indexPath.section == 1) {
        cell.titleLabel.text = @"选择被续投单";
        cell.arrowIcon.hidden = YES;
        cell.contentLabel.text = self.contractCode;
        return cell;
    }
    if (indexPath.section == 3) {
        LKWorkOrderDetailContractCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKWorkOrderDetailContractCell"];
        cell.arrorBtn.hidden = YES;
        cell.titleLabel.text = @"续约声明";
        [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,_shengmingUrl]] placeholderImage:[UIImage imageNamed:@"pic"]];
//        cell.iconImageView.height = 67;
        return cell;
    }
    cell.titleLabel.text = self.titlesArray[indexPath.row];
    if (self.contentsArray.count  > 0) {
      cell.contentLabel.text = self.contentsArray[indexPath.row];
    }else{
        cell.contentLabel.text = @"";
    }
    
    cell.arrowIcon.hidden = YES;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 125;
    }
    return indexPath.section == 3 ? 180 : 43;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.0000000000001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 12;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [[UIView alloc] init];
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = cellHeaderBgColor;
    return view;
}
-(NSArray *)titlesArray{
    if (!_titlesArray) {
        _titlesArray = @[@"出借人",@"合同金额",@"到期金额",@"到期日期",@"应支付利息",@"还款日期"];
    }
    return _titlesArray;
}

/**
 获取订单续投申请的详细信息
 */
-(void)getDetailInformation{
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:getMyContinueApplyDetailUrl header:[LKUserInforTool header] parameters:@{@"Id":self.applyId} progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        NSDictionary *dic = responseObject[@"result"];
        self.contentsArray = @[dic[@"customerName"],[NSString stringWithFormat:@"%@",dic[@"investmentAmount"]],[NSString stringWithFormat:@"%@",dic[@"expirationAmount"]],dic[@"expirationDateTest"],[NSString stringWithFormat:@"%@",dic[@"incomeSum"]],dic[@"repaymentDateTest"]];
        self.contractCode = dic[@"contractCode"];
        self.status = dic[@"statusTest"];
        NSArray *arra = dic[@"orderContinueAttach"];
        NSDictionary *dicc = [arra firstObject];
        self.shengmingUrl = dicc[@"continueAttachUrl"];
        [self.tableView reloadData];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
//-(NSMutableArray *)contentsArray{
//    if (!_contentsArray) {
//        _contentsArray = [[NSMutableArray alloc] init];
//    }
//    return _contentsArray;
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
